#ifndef DSQLITEMGR_H
#define DSQLITEMGR_H

#include <QSqlDatabase>
#include <QSqlRecord>

#include "DHeader.h"
#include "DObjectHeader.h"

class DSqliteMgr
{
public:
    DSqliteMgr();

    void initDB();

    void testDB();

    std::vector<QSqlRecord> execSQL(const QString& strSQL);

    // update data of meme
    void submit(const QDate& dt, IDHomeworkType type,
                const std::vector<DAddHomework>& vecYes);

    std::vector<DHomeworkType> getAllHomework();

    QString getHomeworkTypeName(int nHomeworkTypeID);

    void setStudentData(const std::vector<DStudent>& vecStudent)
    {
        qInfo() << vecStudent.size();
        m_vecStudent = vecStudent;
        std::sort(m_vecStudent.begin(), m_vecStudent.end(),
                  [](const DStudent& d1, const DStudent& d2)
                  { return d1.strNumber < d2.strNumber; });
    }
    void setSubjectData(const std::vector<DSubject>& vecSubject)
    {
        m_vecSubject = vecSubject;
    }

    void setSubmitData(
        const std::map<IDStudent,
                       std::map<QDate, std::vector<DOneHomeworkSubmit>>>&
            mapSubmit)
    {
        m_mapSubmit = mapSubmit;
    }

    std::vector<DUISubmit> getSubmitYesNoData(IDStudent idStudent,
                                              const QDate& dtS,
                                              const QDate& dtE,
                                              IDHomeworkType idType);
    bool getStudent(DStudent& student, int nID) const;
    const std::vector<DSubject>& getAllSubject() const { return m_vecSubject; }
    const std::vector<DStudent>& getAllStudent() const { return m_vecStudent; }

private:
    QSqlDatabase m_db;
    std::vector<DSubject> m_vecSubject;
    std::vector<DStudent> m_vecStudent;
    std::map<IDStudent, std::map<QDate, std::vector<DOneHomeworkSubmit>>>
        m_mapSubmit;
};

D_DECLARE_OBJ(DSqliteMgr, "org.d.DSqliteMgr")

#endif  // DSQLITEMGR_H
